package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrBusinessDurationEfficiencyMapper;
import com.yunhai.device.service.OrrBusinessDurationEfficiencyService;
import com.yunhai.model.entity.orr.OrrBusinessDurationEfficiencyEntity;
import com.yunhai.model.vo.orr.OrrBusinessDurationEfficiencyQuery;
import com.yunhai.model.vo.orr.OrrBusinessDurationEfficiencyVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrBusinessDurationEfficiencyServiceImpl implements OrrBusinessDurationEfficiencyService {

    @Resource
    private OrrBusinessDurationEfficiencyMapper orrBusinessDurationEfficiencyMapper;

    /**
     * 获取 OrrBusinessDurationEfficiency 分页列表
     */
    @Transactional
    public IPage getOrrBusinessDurationEfficiencyPagination(PaginationVo paginationVo, OrrBusinessDurationEfficiencyQuery orrBusinessDurationEfficiencyQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrBusinessDurationEfficiencyEntity> lqs = new LambdaQueryWrapper();
        orrBusinessDurationEfficiencyMapper.selectPage(page, lqs);

        List<OrrBusinessDurationEfficiencyEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrBusinessDurationEfficiency 所有数据
     *
     */
    @Transactional
    public List<OrrBusinessDurationEfficiencyEntity> getOrrBusinessDurationEfficiencyAllList( OrrBusinessDurationEfficiencyQuery orrBusinessDurationEfficiencyQuery ) throws Exception {

        LambdaQueryWrapper<OrrBusinessDurationEfficiencyEntity> lqs = new LambdaQueryWrapper();
        List<OrrBusinessDurationEfficiencyEntity> list = orrBusinessDurationEfficiencyMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrBusinessDurationEfficiency 详情
     */
    @Transactional
    public OrrBusinessDurationEfficiencyEntity getOrrBusinessDurationEfficiencyDetail( Long id) throws Exception {

        OrrBusinessDurationEfficiencyEntity orrBusinessDurationEfficiencyEntity = orrBusinessDurationEfficiencyMapper.selectById(id);
        return orrBusinessDurationEfficiencyEntity;
    }


    /**
     * 新增 OrrBusinessDurationEfficiency
     * */
    @Transactional
    public void addOrrBusinessDurationEfficiency(OrrBusinessDurationEfficiencyVo orrBusinessDurationEfficiencyVo) throws Exception {

        OrrBusinessDurationEfficiencyEntity orrBusinessDurationEfficiencyEntity = new OrrBusinessDurationEfficiencyEntity();
        ReflectionCopy.copyProperties( orrBusinessDurationEfficiencyEntity, orrBusinessDurationEfficiencyVo );
        orrBusinessDurationEfficiencyMapper.insert(orrBusinessDurationEfficiencyEntity);
        return;
    }


    /**
     * 更新 OrrBusinessDurationEfficiency
     * */
    @Transactional
    public void updateOrrBusinessDurationEfficiency( OrrBusinessDurationEfficiencyVo orrBusinessDurationEfficiencyVo) throws Exception {

        if( orrBusinessDurationEfficiencyVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrBusinessDurationEfficiencyEntity orrBusinessDurationEfficiencyEntity = new OrrBusinessDurationEfficiencyEntity();
        ReflectionCopy.copyProperties( orrBusinessDurationEfficiencyEntity, orrBusinessDurationEfficiencyVo );
        orrBusinessDurationEfficiencyMapper.updateById(orrBusinessDurationEfficiencyEntity);
        return;
    }

    /**
     * 删除 OrrBusinessDurationEfficiency
     * */
    @Transactional
    public void batchRemoveOrrBusinessDurationEfficiency( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrBusinessDurationEfficiencyMapper.deleteBatchIds(ids);
    }

}